home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / NeXTtext / text / webster.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-06  |  6.3 KB  |  231 lines

  1.  
  2. #import <stdio.h>
  3.  
  4. #import <btree/BTree.h>
  5. #import <btree/BTreeCursor.h>
  6. #import <btree/BTreeFile.h>
  7.  
  8. /* main sections of the book */
  9. #define dMain            0
  10. #define dAbbr            1
  11. #define dForeign        2
  12. #define dBio            3
  13. #define dGeo            4
  14. #define dCollege        5
  15. #define dAbbrD            6
  16. #define dThesaurus        7
  17.  
  18. /* Tags for Webster Dictionary entries */
  19. #define dEntry            1
  20. #define dPronunciation        2
  21. #define dVariant        3
  22. #define dFunction        4
  23. #define dInflection        5
  24. #define dPicture        6
  25. #define dDate            7
  26. #define dSubject        8
  27. #define dEtymology        9
  28. #define dSense            11
  29. #define dWordlist        12
  30. #define dUsage            13
  31.  
  32. /* 1-byte escapes used in Webster */
  33. #define dROMAN            14
  34. #define dITALIC            15
  35. #define dBOLD            16
  36. #define dSCHWA            17
  37. #define dHACCENT        18
  38. #define dLACCENT        19
  39. #define dBOLDCOLON        20
  40. #define dELONG            21
  41. #define dADIER            22
  42. #define    dSUP            23
  43. #define dSUB            24
  44. #define    dOLONG            25
  45. #define dALONG            26
  46. #define dILONG            27
  47. #define dGFONT            28
  48. #define dODOT            29
  49. #define dSMALLCAP        30
  50. #define dBITALIC        31
  51. #define dESCAPE1        10
  52. #define dESCAPE2        127
  53.  
  54. /* Tags for the Collegiate Thesaurus: */
  55. #define tEntry             1
  56. #define tVariant         2
  57. #define tFunction         3
  58. #define tSense            4
  59. #define tSyn             5
  60. #define tAnt             6
  61. #define tCon             7
  62. #define tRel             8
  63. #define tIdiom             9
  64. #define tBracket         10
  65. #define tCompare         11
  66. #define tLimited         12
  67. #define tItalic         13
  68. #define tBold             14
  69. #define tRoman             15
  70. #define tBItalic         16
  71. #define tSmallCap         17
  72. #define tCommaSpace         18
  73. #define tSemicolonSpace     19
  74. #define tMaxSpecial         19
  75.  
  76. typedef struct SenseList
  77. /*
  78.  * A SenseList is a tagged list of fields:
  79.  *   s[0] is the tag (e.g., dEntry, dFunction, tEntry, etc)
  80.  *   s+1 is the data.
  81.  */
  82. {
  83.     char *s;
  84.     int n;
  85.     struct SenseList *next;
  86. } SenseList;
  87.  
  88. typedef int entryID;
  89.  
  90. typedef struct
  91. /*
  92.  * A Definition entry contains any of a number of fields (all optional).
  93.  * The field pointers are mostly taken from the SenseList,
  94.  * so if there happens to be, e.g., more than one function field,
  95.  * only the first function field appearing the list is pointed to
  96.  * by the "function" field.  Thus the field pointers point to the
  97.  * first of 0 or more such fields which may be present in the entry.
  98.  */
  99. {
  100.     char *entry;        /* the main entry word */
  101.     char *dotted;        /* the dotted form of the word (hyphenation info) */
  102.     char *pronunciation;    /* the pronunciation field */
  103.     char *function;        /* the grammatical function (n, v, adj, etc) */
  104.     char *date;        /* date word was first used */
  105.     char *etymology;    /* etymological description */
  106.     char *inflection;    /* inflected forms (-ed, -ies, -ing, etc) */
  107.     char *variant;        /* variant forms and inflections */
  108.     char *picture;        /* pathname of file containing picture, if any */
  109.     char *subject;        /* internal subject codes, per-sense */
  110.     SenseList *l;        /* linked list of senses comprising the entry */
  111.     int section;        /* one of: dMain, dAbbr, dForeign, dBio, dGeo, etc */
  112.     entryID ID;        /* ID of entry in book */
  113.     struct ReferenceBook *book;    /* what book it came from */
  114. } Definition;
  115.  
  116. typedef struct ReferenceBook
  117. /*
  118.  * For now, a reference book from Webster includes a tagged source file,
  119.  * an index, and possibly also a full-text index.
  120.  * This data structure also contains pointers to book-specific i/o routines.
  121.  */
  122. {
  123.     BTreeFile    *source;
  124.     BTreeCursor    *entryCursor,
  125.                 *indexCursor,
  126.                 *headwordIndexCursor,
  127.                 *fullIndexCursor;
  128.     entryID        *entryList;
  129.     int            entryListNum, entryListCount;
  130.     Definition    *(*getDef)();
  131.     int            (*putDef)(), (*freeDef)();
  132. } ReferenceBook;
  133.  
  134. /* conversion formats for special characters -- see dictionaryOutputFormat */
  135. #define W_ASCII        0
  136. #define W_PS        1
  137. #define W_TROFF        2
  138. #define W_VERBOSE    3
  139.  
  140. ReferenceBook *referenceOpen(char *name);
  141.     /*
  142.      * Open reference 'bookName' for searching and return it.
  143.      * Currently 'bookName' may be one of 'Webster-Dictionary' or 'Webster-Thesaurus'.
  144.      * Return the 'ReferenceBook' if successful, 0 if not.
  145.      */
  146.  
  147. int referenceClose(ReferenceBook *r);
  148.     /*
  149.      * Close and free 'book'
  150.      */
  151.  
  152. char *referencePath();
  153.  
  154. int freeDefinition(Definition *d);
  155.     /*
  156.      * Free up space used by 'd'.
  157.      */
  158.  
  159. int dictionarySection(ReferenceBook *book, entryID itsID);
  160.     /*
  161.      * Return the the section in Webster's Ninth which includes 'offset'.
  162.      * 'websterSectionName[...]' gives the string value for it.
  163.      */
  164.  
  165. extern char *websterSectionName[]; /* ...[i] is the name of the ith section (dMain, etc) */
  166.  
  167. Definition *
  168. nextDefinition(ReferenceBook *book);
  169.     /*
  170.      * Read and return the next definition from 'book'.
  171.      * Use this to step through the list of definitions in the book:
  172.      *    while (d = nextDefinition(dictionary))
  173.      *        putDefinition(d,0);
  174.      */
  175.  
  176. Definition *
  177. getDefinition(char *word, ReferenceBook *book, int match);
  178.     /*
  179.      * Get the first definition for 'word' in 'book' and return it, or NULL if none found.
  180.      * If 'exact' is true, the word must match exactly, otherwise
  181.      * prefix matches are accepted.
  182.      */
  183.  
  184. Definition *
  185. getNextDefinition(char *word, ReferenceBook *book, int match);
  186.     /*
  187.      * Return the next definition matching 'word', NULL if no more.
  188.      * Call this after 'getDefinition(...)'.
  189.      */
  190.  
  191. Definition *
  192. seekEntry( entryID itsID, ReferenceBook *book);
  193.     /*
  194.      * Return the definition with the given ID, if it exists.
  195.      */
  196.  
  197. int useFullTextIndex( ReferenceBook *book,  int useFullText);
  198.     /*
  199.      * Used to set whether the full-text or headword index is used.
  200.      * Returns 1 iff index requested exists.
  201.     */
  202.  
  203. int freeDefinitions(Definition *D[]);
  204.     /*
  205.      * Free the definitions in 'D' (null-terminated; see 'getDefinitions()'.
  206.      */
  207.      
  208. int getDefinitions(char *word, ReferenceBook *book, int exact, Definition *D[], int max);
  209.     /*
  210.      * Get up to 'max' definitions of 'word' and put them in 'D'.
  211.      * 'D' will be null-terminated (thus, it must hold max+1 items).
  212.      * Return the number found.
  213.      */
  214.  
  215. int putDefinition(Definition *d, int (*output)());
  216.     /*
  217.      * Output the definition 'd', calling the function 'output'
  218.      * for each character of data.  The information is preconverted
  219.      * at lookup time to some output format (dictionaryOutputFormat,
  220.      * one of W_ASCII, W_PS, etc).  If no output function is given
  221.      * the information is written to the standard output.
  222.      */
  223.  
  224. extern int
  225.    dictionaryOutputFormat, /* format: W_ASCII (default), W_PS, W_TROFF, W_VERBOSE */
  226.    dictionaryFoldSenses;   /* fold lines to this many characters (0 default) */
  227.  
  228.  
  229.  
  230.       
  231.